<template>
    <div class="wp">
        <div class="left">
            <span v-for="item in storeChart.toolMeun" :key="item.type">
                <i v-if="item.show && item.isbar != 2" :title="item.type" class="iconfonMy" :class="item.icon"
                    @click.stop="changeNavTap(item, $event)">{{
                        item.name
                    }}</i>
            </span>

        </div>
        <div class="right">
            <!-- <span @click="createLogin('发现')">发现</span> -->
            <!-- <span @click.stop="createLogin('模板')">模板</span> -->
            <span @click.stop="createLogin('账户')">账户</span>
            <!-- <span @click.stop="createLogin('资讯')">资讯</span> -->
            <!-- <span @click.stop="createLogin('个性化')">个性化</span> -->
            <span @click.stop="createLogin('系统工具')">系统工具</span>
            <span @click.stop="createLogin('帮助')">帮助</span>
        </div>
        <rightView v-if="showRightView" :rightViewMenu="storeChart.toolMeun" :rightViewType="rightViewType" />
    </div>
</template>
<script setup>
import { onMounted, onUnmounted, ref } from 'vue'
import { mainStore, chartStore } from '@/store/index.js'
const { ipcRenderer, shell } = require('electron');
import bus from '@/utils/bus.js'

import rightView from '@/components/tools/right_view.vue'


const storeMain = mainStore()
const storeChart = chartStore()
const showRightView = ref(false)
const rightViewType = ref(null)



onMounted(() => {
    let toolMeun = localStorage.getItem('headToolMenuInfo')
    if (toolMeun) {
        storeChart.changeToolMeun(JSON.parse(toolMeun))
    }
    let v = localStorage.getItem('selectHuTuList')
    v = v ? JSON.parse(v) : []
    let arr = storeChart.toolMeun.slice(-2)
    let arr1 = storeChart.toolMeun.splice(0, 23)
    v.sort((a, b) => JSON.parse(a).idx - JSON.parse(b).idx);
    let huatuGj = v.map(item => {
        item = JSON.parse(item)
        return {
            show: true, isbar: 1, name: '', type: item.type, icon: item.icon, isxian: true
        }
    })
    storeChart.changeToolMeun([...arr1, ...huatuGj, ...arr])
})

const changeNavTap = (v, event) => {
    ipcRenderer.send('hide-right-click-menu')
    let e = v.type
    if (e == '刷新') {
        window.location.reload()
    }
    if (e == '报价') {
        storeChart.changeBodyType('list')
        bus.emit('qie_hang_qing')
    }
    if (e == '账户窗口') {
        ipcRenderer.send('right_click_msg', { type: '打开下单' })
    }
    if (e == '画线下单') {
        ipcRenderer.send('open-huaxiadanOption',{ configInfo: JSON.stringify(storeMain.ConfigJsInfo) })
    }
    if (e == '画线单列表') {
        ipcRenderer.send('open-huaxianlist',{ configInfo: JSON.stringify(storeMain.ConfigJsInfo) })
    }
    if (e == '预警列表') {
        ipcRenderer.send('open-yujinglist')
    }
    if (e == '分时' || e == 'K线' || e == '1分钟' || e == '3分钟' || e == '5分钟' || e == '15分钟' || e == '30分钟' || e == '一小时' || e == '二小时' || e == '四小时' || e == '日线') {
        storeChart.changeBodyType('chart')
        storeChart.changeKlineAPiVal(e)
        if (e == '分时') {
            storeChart.changeSelectbodyChartListTab('分时图')
        } else {
            storeChart.changeSelectbodyChartListTab('K线图')
        }
    }
    if (e == '其他按钮') {
        storeMain.setRightViewXY(event)
        rightViewType.value = '其他按钮'
        showRightView.value = true
    }
    storeChart.changeHeadApiVal(v)
}

bus.on('hideRightView', () => {
    showRightView.value = false
})

onUnmounted(() => {
    bus.off('hideRightView')
})
const createLogin = (type) => {
    let TypeName = ''
    switch (type) {
        case '发现':
            shell.openExternal('https://www.wenhua.com.cn/guide/fx.html');
            break;
        case '模板':
            TypeName = 'rightClickMuBan'
            break;
        case '账户':
            TypeName = 'rightClickZhangHu'
            break;
        case '资讯':
            TypeName = 'rightClickZIxun'
            break;
        case '个性化':
            TypeName = 'rightClickGeXingHua'
            break;
        case '系统工具':
            TypeName = 'rightClickXiTongGongJu'
            break;
        case '帮助':
            TypeName = 'rightClickBangZhu'
            break;
    }
    if (TypeName) {
        ipcRenderer.send('open-right-click', { TypeName: TypeName, x: 13, y: 10 })
    }
}
</script>
<style scoped lang="less">
.wp {
    background: #23262a;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px 0 5px;
    line-height: 35px;
    min-width: 1210px;

    .left {
        flex: 1;
        overflow: hidden;
        white-space: nowrap;

        i {
            display: inline-block;
            font-size: 18px;
            padding: 0 4px;
            font-style: normal;
            width: 30.2px;
            text-align: center;
            font-family: 'Eras Light ITC';
        }

        .set_size {
            font-size: 14px;
        }

        i:hover {
            background-color: #43484e;
        }
    }

    .right {
        text-align: right;

        span {
            display: inline-block;
            padding: 0 7.5px;
        }

        span:hover {
            background-color: #43484e;
        }
    }
}
</style>